package com.sporfirio.project1;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceive extends BroadcastReceiver{
	
	public void onReceive(Context context, Intent intent) {
		if(intent.getAction().equals("android.intent.action.DATA_SMS_RECEIVED")){
		Bundle bundle = intent.getExtras();
		
		if (bundle != null) {
			Object[] pdus = (Object[]) bundle.get("pdus");
			final SmsMessage[] messages = new SmsMessage[pdus.length]; 
			for (int i=0; i<messages.length; i++) {
				messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
		}
			if(messages.length > -1){
				//if(messages[0].getMessageBody().equals("me encontre")){
				String msg = messages[0].getMessageBody().toLowerCase().toString();
				String msg1 = "me encontre";
				if(msg.contains(msg1)){
					Intent it = new Intent("SEND_SMS");
					Toast.makeText(context, "SMS RECEBIDO", Toast.LENGTH_LONG).show();
					//it.putExtra(msg, true);
					context.startService(it);
				}
			}
		
	}
}
		
		
		/*if(intent.getAction().equals("android.intent.action.AIRPLANE_MODE")){
			/*Bundle bundle = intent.getExtras();
			
			if (bundle != null) {
				Object[] pdus = (Object[]) bundle.get("pdus");
				final SmsMessage[] messages = new SmsMessage[pdus.length]; 
				for (int i=0; i<messages.length; i++) {
					messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
			}
				if(messages.length > -1){
					if(messages[0].getMessageBody().equals(dados.getPassword())){*/
						Intent it = new Intent("SEND_SMS");
						Toast.makeText(context, "o broadcast iniciou", Toast.LENGTH_LONG).show();
						context.startService(it);
					//}
				//}
			
		//}
	//}
		

}
	

}
